﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class RZTriggerListener : MonoBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerEnterHandler,
IPointerExitHandler, IPointerUpHandler, IRZRaycast
{
    public delegate void VoidColliderDelegate(GameObject go, PointerEventData eventData);
    public event VoidColliderDelegate OnClick;
    public event VoidColliderDelegate OnDown;
    public event VoidColliderDelegate OnEnter;
    public event VoidColliderDelegate OnExit;
    public event VoidColliderDelegate OnUp;


    public bool RaycastValid = true;

    static public RZTriggerListener Get(GameObject go)
    {
        RZTriggerListener listener = go.GetComponent<RZTriggerListener> ();
        if (listener == null) listener = go.AddComponent<RZTriggerListener> ();
        return listener;
    }

    public bool IsRaycastValid()
    {
        return RaycastValid;
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        Debug.Log ($"OnPointerClick");
        if (OnClick != null) OnClick (gameObject, eventData);
    }

    public void OnPointerDown(PointerEventData eventData)
    {
        if (OnDown != null) OnDown (gameObject, eventData);
    }

    public void OnPointerEnter(PointerEventData eventData)
    {
        if (OnEnter != null) OnEnter (gameObject, eventData);
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        if (OnExit != null) OnExit (gameObject, eventData);
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        if (OnUp != null) OnUp (gameObject, eventData);
    }
}
